package com.hyfrogx.modules.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.app.entity.HyUserAttentionEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liubin
 * @date 2019/10/28 13:19
 */
@Mapper
public interface AttentionDao extends BaseMapper<HyUserAttentionEntity> {

  @Select("SELECT\n" +
    "\tsid\n" +
    "FROM\n" +
    "\thy_information_verify v\n" +
    "\tLEFT JOIN hy_user_attention a on v.uid=a.sid \n" +
    "WHERE\n" +
    "\tv.enable_state = 1\t\t\n" +
    "\t\tand fid = #{userId}\n")
  List<HyUserAttentionEntity> getAllFollowId(@Param("userId") Long userId);

  @Select("select t.sid as sid,t.fid as fid,u.username as username,u.head as\n" +
    "\t\thead,t.created as created,u.signature as signature,\n" +
    "\t\t(select count(id) as sum from hy_user_attention a where a.fid = t.sid and\n" +
    "\t\ta.sid= t.fid limit 1) as sta\n" +
    "\t\tfrom hy_user_attention t\n" +
    "\t\tLEFT JOIN hy_user u on u.uid = t.fid\n" +
    "\t\twhere t.sid = #{map.sid}")
  List<HyUserAttentionEntity> getMyFunsByUid(QueryExt query, @Param("map") Map map);

  @Select("select b.sid,a.rid,b.fid, a.uid as useruid, a.rid as userrid, a.phone as\n" +
    "\t\tphone, a.head as head, a.account as account,a.username , a.sex,\n" +
    "\t\ta.email,\n" +
    "\t\ta.signature,\n" +
    "\t\ta.birthday, a.status,\n" +
    "\t\tb.created\n" +
    "\t\tfrom\n" +
    "\t\thy_user a LEFT JOIN hy_user_attention b on a.uid=b.sid where\n" +
    "\t\tb.fid=#{map.fid,jdbcType=INTEGER}\n" +
    "\t\torder by b.created desc")
  List<HyUserAttentionEntity> getAllSunSid(QueryExt query, @Param("map") Map map);

  @Select("select\n" +
    "\t\tsid,fid\n" +
    "\t\tfrom\n" +
    "\t\thy_user_attention\n" +
    "\t\twhere sid= #{sid}\n" +
    "\t\tand fid =#{fid}")
  HyUserAttentionEntity getBySidAndUid(@Param("sid") Integer sid, @Param("fid") Integer fid);

  @Select("select b.sid,b.fid,a.uid as useruid, a.rid as userrid, a.phone as\n" +
    "\t\tphone, a.head as head, a.account as account,a.username , a.sex,\n" +
    "\t\ta.email,\n" +
    "\t\ta.signature,\n" +
    "\t\ta.birthday, a.status,\n" +
    "\t\tb.created, a.token\n" +
    "\t\tfrom\n" +
    "\t\thy_user a LEFT JOIN hy_user_attention b on a.uid=b.fid where\n" +
    "\t\tb.sid=#{map..sid,jdbcType=INTEGER}")
  List<HyUserAttentionEntity> getAllFunsId(QueryExt query, @Param("map") Map map);

  @Select("select\n" +
    "\t\t*\n" +
    "\t\tfrom hy_user_attention\n" +
    "\t\twhere fid = #{fid,jdbcType=INTEGER} limit\n" +
    "\t\t1")
  HyUserAttentionEntity getByFid(Integer fid);
}
